package com.link.base.task;

import com.link.base.base.statistics.service.StatisticsService;
import com.link.base.core.basic.config.xxljob.BaseLinkJobHandler;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 知识库、论坛、案例库工作流
 * 用于定时将存储在redis中的浏览量、阅读人数、点赞数、收藏数回写到相对应的数据库
 * 
 * @author ouyangzhenqiang
 * @date 2019/03/06 22:26
 */
@JobHandler(value = "TaskWriteStatisticsToDB")
@Component
public class TaskWriteStatisticsToDB extends BaseLinkJobHandler {
    @Resource
    private StatisticsService statisticsService;

    @Override
    public ReturnT<String> execute(String strings) throws Exception {
        try {
            statisticsService.writeBackFromRedisToDB();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log(e.getMessage());
            return ReturnT.FAIL;
        }
    }
}
